// 选择分支 不含tag
// projectId: 必传
import React from 'react';
import { Select } from '@teamix/ui';
import { Title } from '@alife/devops-ui';
import intl from '../../locale';

export default class BranchSelect extends React.Component {
  selectBranch = (value) => {
    const { onChange } = this.props;
    onChange && onChange(value);
  };

  render() {
    const { value, allBranches, onChange, ...others } = this.props;
    const dataSource = allBranches.map((item) => {
      return {
        label: item.name,
        value: item.name,
      };
    });
    return (
      <Select
        placeholder={intl.get({
          id: 'code-assets.components.branchSelect.SelectABranch',
          defaultMessage: '请选择分支',
        })}
        dataSource={dataSource}
        value={value}
        showSearch
        onChange={this.selectBranch}
        popupProps={{
          className: 'ellipsis-label-select-popup',
        }}
        itemRender={(item) => {
          return (
            <Title trigger={<span>{item.label}</span>} align="t">
              {item.label}
            </Title>
          );
        }}
        {...others}
      />
    );
  }
}
